<?php

namespace App\Http\Controllers\Wechat\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\UserCouponRequest;
use App\Repos\UserCouponRepo;

class UserCouponController extends Controller
{
    public function index(UserCouponRequest $request)
    {
    	$rs['status'] = false;
    	$where['user_id'] = $request->user_id;    	
    	$where['is_used'] = 0;  // 未被使用得券
        if($request->shop_id) {
            $where['shop_id'] = $request->shop_id;
        }
    	$list = UserCouponRepo::getPages($where,$num=10);
    	if($list) {
    		$rs['status'] = true;
    		$rs['data'] = $list;
    		return response()->json($rs)->setEncodingOptions(JSON_NUMERIC_CHECK);
    	}
    	return response()->json($rs);
    }
}
